package com.ketangpai.admin.controller;

import com.ketangpai.admin.entity.Course;
import com.ketangpai.admin.service.ClassDetailService;
import com.ketangpai.admin.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/classDetail")
@Api(tags = "课程详情")
public class ClassDetailController {

    @Resource
    private ClassDetailService classDetailService;

    @ApiOperation(value = "课程信息")
    @PostMapping("/information")
    public JsonResult<?> getCourseInformation(@RequestBody Map<String, Integer> params) {
        Integer courseId = params.get("courseId");
        if (courseId== null) {
            return JsonResult.error("courseId不能为空");
        }

        Course course = classDetailService.getCourseInformation(courseId);
        if (course == null) {
            return JsonResult.error("未找到课程信息");
        }
        System.out.println("course:"+course);

        Map<String, Object> result = new HashMap<>();
        result.put("course", course);
        return JsonResult.success(result);
    }

}
